$(function() {
    $(document).on('click', '[data-role="commentSetting-del"]', function() {
        $(this).parent('.commentSetting-item').remove();
    })

    $('[data-role="commentSetting-add"]').on('click', function() {
        var html = '<div class="commentSetting-item">\
                        <input type="text" class="commentSetting-text">\
                        <input type="radio" name="commentSetting" class="commentSetting-radio">\
                        <span data-role="commentSetting-del" class="commentSetting-del"></span>\
                    </div>';
        $('.commentSetting-inner').append(html);
    })

    // 提交数据
    $('[data-role="commentSetting-submit"]').on('click', function() {
        var $input = $('.commentSetting .commentSetting-text');
        var $radio = $('.commentSetting .commentSetting-radio');
        var scoreItemsJson = [];

        for(var i = 0, len = $input.length;i < len;i++) {
            var val  = $input.eq(i).val();
            var flag = $radio.eq(i).attr('checked');
            var obj = {};
            if(val.trim() != '') {
                obj.name = val;
                if(flag) {
                    obj.checked = 1;
                } else {
                    obj.checked = 0;
                }

                scoreItemsJson.push(obj);
            }

        }
        console.log(scoreItemsJson)
    })
})
